package com.yxt.dispatch.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.yxt.dispatch.entity.FormItemEntity;
import com.yxt.dispatch.service.FormItemService;
import com.yxt.dispatch.vo.FormItemVO;
import com.yxt.dispatch.vo.FormItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yxt.dispatch.entity.FormItemEntity;
import com.yxt.dispatch.service.FormItemService;
import com.yxt.common.utils.PageUtils;
import com.yxt.common.utils.R;



/**
 * 表单项表 
 *
 * @author august
 * @email 379249906@qq.com
 * @date 2020-08-13 13:43:27
 */
@RestController
@RequestMapping("/formitem")
public class FormItemController {
    @Autowired
    private FormItemService formItemService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = formItemService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{formItemId}")
    public R info(@PathVariable("formItemId") Long formItemId){
		FormItemEntity formItem = formItemService.getById(formItemId);

        return R.ok().put("formItem", formItem);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody FormItemEntity formItem){
		formItemService.save(formItem);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FormItemEntity formItem){
		formItemService.updateById(formItem);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] formItemIds){
		formItemService.removeByIds(Arrays.asList(formItemIds));

        return R.ok();
    }


    /**
     * 返回需要的表单项
     */
    @RequestMapping("/form")
    public R formItem(String areaName,String formName){
       // PageUtils page = formItemService.queryPage(params);
       // return R.ok().put("page", page);
        List<FormItemVO> form = formItemService.formItem(areaName, formName);
        return R.ok().put("data",form);
    }

}
